package com.xinyuan.trade.Activity;

import android.content.res.Resources;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xinyuan.trade.R;
import com.xinyuan.trade.Dialog.ShareDialog;
import com.xinyuan.trade.Entity.DynamicEntity;
import com.xinyuan.trade.Entity.NewEntity;
import com.xinyuan.trade.Utils.Utils;

/**
 * 新闻详细页
 * 
 * @author daiye
 * 
 */
public class DynamicDetailActivity extends BaseActivity implements
		OnClickListener {

	public static final String EXTRA_DYNAMICID = "dynamicid";
	private Resources resources;

	private RelativeLayout layout_top;

	private Button btn_back;
	private TextView tv_top;
	private Button btn_share;
	// private ScrollViewExtend layout_scroll;
	// private LoadingView layout_loading;
	private DynamicEntity.Data data;
	// private int newid;
	private TextView tv_content;
	private TextView tv_ptime;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_dynamic_detail);

		resources = getResources();

		layout_top = (RelativeLayout) findViewById(R.id.layout_top);
		uiAdapter.setMargin(layout_top, LayoutParams.MATCH_PARENT, 60, 0, 0, 0,
				0);

		btn_back = (Button) findViewById(R.id.btn_back);
		uiAdapter.setMargin(btn_back, 50, uiAdapter.CalcHeight(50, 50, 50), 0,
				0, 0, 0);
		btn_back.setOnClickListener(this);

		tv_top = (TextView) findViewById(R.id.tv_top);
		uiAdapter.setTextSize(tv_top, 26);

		btn_share = (Button) findViewById(R.id.btn_share);
		uiAdapter.setMargin(btn_share, 50, uiAdapter.CalcHeight(50, 50, 50), 0,
				0, 0, 0);
		btn_share.setOnClickListener(this);

		data = (DynamicEntity.Data) getIntent().getSerializableExtra(
				EXTRA_DYNAMICID);
		initView();
		initData(data);

		// newid = getIntent().getIntExtra(EXTRA_NEWID, -1);
		// if (newid == -1) {
		// Toast.show(self, "新闻已被删除！");
		// finish();
		// } else {
		// initView();
		// initData(newid);
		// }
	}

	private void initView() {
		tv_ptime = (TextView) findViewById(R.id.tv_ptime);

		tv_content = (TextView) findViewById(R.id.tv_content);
	}

	private void initData(DynamicEntity.Data data) {

		tv_content.setText(Html.fromHtml(data.getContent()));

		tv_ptime.setText(Utils.formatDataByDay(Integer.parseInt(data
				.getUpdatetime())));
	}

	// private void initData(int newid) {
	// NetUtils.getValue(self, Config.BACKGROUND, new NetCallBack() {
	//
	// @Override
	// public void success(String json) {
	// layout_scroll.setVisibility(View.VISIBLE);
	// layout_loading.postHandle(LoadingView.success);
	// layout_loading.setVisibility(View.GONE);
	// BackGroundEntity entity = new Gson().fromJson(json,
	// BackGroundEntity.class);
	//
	// List<BackGroundEntity.Data> data = entity.getData();
	//
	// }
	//
	// @Override
	// public void failed(String msg) {
	// layout_loading.postHandle(LoadingView.interfaceerror);
	// layout_loading.setL(l);
	// }
	// });
	// }
	//
	// RequestWebListener l = new RequestWebListener() {
	//
	// @Override
	// public void requestWeb() {
	// initData(newid);
	// }
	// };

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;
		case R.id.btn_share:
			new ShareDialog(self, "心园经贸，常熟世纪心园集团出品！");
			break;
		default:
			break;
		}
	}
}
